package com.aistar.service.myfoot.impl;

import com.aistar.mapper.FootprintMapper;
import com.aistar.mapper.MemberMapper;
import com.aistar.pojo.Footprint;
import com.aistar.pojo.FootprintExample;
import com.aistar.pojo.Member;
import com.aistar.service.myfoot.MyfootService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * @author shkstart
 * @date 2019/10/1 - 21:21
 */
@Service
public class MyfootServiceImpl implements MyfootService, Serializable {

    @Autowired
    private FootprintMapper footprintMapper;
    @Autowired
    private MemberMapper memberMapper;
    @Override
    public int setMyfoot(String province, String city, java.util.Date mydata, int myId) {
        Footprint footprint = new Footprint();

        FootprintExample footprintExample = new FootprintExample();
        FootprintExample.Criteria criteria = footprintExample.createCriteria();
        criteria.andFootDistrictEqualTo(city);
        criteria.andFootUserIdEqualTo(myId);
        int value = 0;
        if(footprintMapper.selectByExample(footprintExample) != null){
            System.out.println("!=null");
            if(footprintMapper.selectByExample(footprintExample).size() != 0){
                if(footprintMapper.selectByExample(footprintExample).get(0).getFootDistrict().equals(city) == true){
                    System.out.println("selectByExample");
                    value = 0;
                }
            }
            if(footprintMapper.selectByExample(footprintExample).size() == 0){
                footprint.setFootUserId(myId);
                footprint.setFootDistrict(city);
                footprint.setFootProvinces(province);
                footprint.setFootDate(mydata);
                int result = footprintMapper.insert(footprint);
                System.out.println("insert");
                value = result;
            }
        }
        return value;
    }

    @Override
    public Member selectUserById(int userid) {
        return memberMapper.selectByPrimaryKey(userid);
    }
}
